package com.ptma.repository;

import java.io.Serializable;
import java.util.List;

import javax.persistence.PersistenceException;
import javax.transaction.Transactional;

import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ptma.dao.GenericDao;

@Repository
public class GenericRepo<T extends Serializable, ID extends Serializable> {

	@Autowired
	private GenericDao<T, ID> dao;

	@Transactional
	public T save(ID objToSave) throws PersistenceException,
			ConstraintViolationException {

		return dao.save(objToSave);

	}

	@Transactional
	public List<T> findAllById(ID objtToFind) {
		return dao.findAllById(objtToFind);
	}

	@Transactional
	public T findById(ID objtToFind) {
		return dao.findById(objtToFind);
	}

	public boolean isExist(ID objToCheck) {
		return false;
	}

	public void saveOrUpdate(ID objToSave) throws PersistenceException,
			ConstraintViolationException {

		dao.saveOrUpdate(objToSave);
	}

	public void update(ID objToUpdate) throws PersistenceException {
		dao.update(objToUpdate);
	}

	public void delete(T objToDelete) throws PersistenceException,
			ConstraintViolationException {

		dao.delete(objToDelete);
	}
}
